package k4_thread.demo07;

public class Service {
    public static void main(String[] args) {

        WaitNotify waitNotify = new WaitNotify();

        new Thread(()->waitNotify.waitMethod(),"wait").start();
        new Thread(()-> waitNotify.notifyMethod(),"notify").start();

    }
}

class WaitNotify{
    public synchronized void waitMethod(){
        try {
            System.out.println(Thread.currentThread().getName()+"执行了 wait 方法 释放了锁");
            wait();
            System.out.println("调用wait方法后执行的内容");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    public synchronized void notifyMethod(){
        try {
            System.out.println(Thread.currentThread().getName()+"执行了 notify 方法 被唤醒");
            notify();
            System.out.println("调用notify方法后执行的内容");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
